package tc.de.krawallmann.robobridge.devices.implementation;

import tc.de.krawallmann.robobridge.communication.Command;
import tc.de.krawallmann.robobridge.communication.CommandType;
import tc.de.krawallmann.robobridge.devices.AbstractDevice;
import tc.de.krawallmann.robobridge.devices.Robot;
import tc.de.krawallmann.robobridge.util.BitOperations;
import tc.de.krawallmann.robobridge.util.MathUtil;

public class RNControl extends AbstractDevice {

	public static final String RNCONTROL_SERVO_POSITION = "RNCONTROL_SERVO_POSITION";
	public static final String RNCONTROL_LEDS = "RNCONTROL_LEDS";
	public static final int SET_SERVO_COMMAND = 1;
	public static final int SET_LED_COMMAND = 2;
	private Servo servo=new Servo(this);
	private int leds;

	public Servo getServo() {
		return this.servo;
	}

	public int getLeds() {
		return this.leds;
	}

	public void setLeds(int leds) {
		int old = this.leds;
		this.leds = leds;
		firePropertyChange(RNCONTROL_LEDS, old, leds);
		getRobot().queueOutgoingCommand(
				new Command(CommandType.UPDATE_ROBOT_DEVICE, false, getDeviceId(), SET_LED_COMMAND,
						leds));
	}

	

	public RNControl(Robot robot, int deviceId) {
		super(robot, AbstractDevice.DEVICE_ID_RP6_RNCONTROL, deviceId, "Roboternetz", "RN-Control");
	}

	@Override
	public boolean onCommandReceived(Command command) {
		if (containsRelevantData(command, Integer.class, Integer.class)) {
			if((Integer)command.getParameter(1)==1){
				//Servo
				servo.setServoPositionInternal((Integer)command.getParameter(2));
				return true;
			}
		}
		return false;
	}

}
